<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOwnerItemsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('owner_items', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('owner_id');
            $table->foreign('owner_id')->references('id')->on('owners')->onDelete('cascade');
            $table->unsignedInteger('count')->comment('第几期付房租');
            $table->dateTime('pay_at')->comment('支付时间')->nullable();
            $table->decimal('rent', 10, 2)->comment('本期租金');
            $table->text('other_amount')->comment('其他金额')->nullable();
            $table->string('status')->comment('还款状态')->default(\App\Models\OwnerItem::STATUS_PAY_PENDING);
            $table->decimal('total_amount',10, 2)->comment('总金额')->nullable();
            $table->dateTime('started_at')->nullable()->comment('本期收租时间');
            $table->dateTime('ended_at')->nullable()->comment('本期最晚收租时间, 默认收租时间 + 1个月');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('owner_items');
    }
}
